home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / JFC.bin / Box.java < prev    next >
Text File  |  1998-06-30  |  37KB  |  1,131 lines

  1. /*
  2.  * @(#)Box.java    1.26 98/04/09
  3.  *
  4.  * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
  5.  *
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  *
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  *
  19.  */
  20.  
  21.  
  22. package com.sun.java.swing;
  23.  
  24. import java.awt.*;
  25. import java.awt.event.*;
  26. import java.beans.PropertyChangeListener;
  27. import java.util.Locale;
  28. import java.io.Serializable;
  29. import com.sun.java.accessibility.*;
  30.  
  31. /**
  32.  * A lightweight container 
  33.  * that uses a BoxLayout object as its layout manager.
  34.  * Box provides several class methods
  35.  * that are useful for containers using BoxLayout --
  36.  * even non-Box containers.
  37.  *
  38.  * <p>
  39.  *
  40.  * The Box class can create several kinds
  41.  * of invisible components 
  42.  * that affect layout:
  43.  * glue, struts, and rigid areas.
  44.  * If all the components your Box contains 
  45.  * have a fixed size,
  46.  * you might want to use a glue component
  47.  * (returned by <code>createGlue</code>)
  48.  * to control the components' positions.
  49.  * If you need a fixed amount of space between two components,
  50.  * try using a strut
  51.  * (<code>createHorizontalStrut</code> or <code>createVerticalStrut</code>).
  52.  * If you need an invisible component
  53.  * that always takes up the same amount of space,
  54.  * get it by invoking <code>createRigidArea</code>.
  55.  * <p>
  56.  * Warning: serialized objects of this class will not be compatible with
  57.  * future swing releases.  The current serialization support is appropriate 
  58.  * for short term storage or RMI between Swing1.0 applications.  It will
  59.  * not be possible to load serialized Swing1.0 objects with future releases
  60.  * of Swing.  The JDK1.2 release of Swing will be the compatibility
  61.  * baseline for the serialized form of Swing objects.
  62.  *
  63.  * @see BoxLayout
  64.  *
  65.  * @author  Timothy Prinzing
  66.  * @version 1.26 04/09/98
  67.  */
  68. public class Box extends Container implements Accessible {
  69.  
  70.     /**
  71.      * Creates a <code>Box</code> that displays its components
  72.      * along the the specified axis.
  73.      *
  74.      * @param axis  can be either <code>BoxLayout.X_AXIS</code>
  75.      *              (to display components from left to right) or
  76.      *              <code>BoxLayout.Y_AXIS</code>
  77.      *              (to display them from top to bottom)
  78.      * @see #createHorizontalBox
  79.      * @see #createVerticalBox
  80.      */
  81.     public Box(int axis) {
  82.     super();
  83.     super.setLayout(new BoxLayout(this, axis));
  84.     }
  85.  
  86.     /**
  87.      * Creates a <code>Box</code> that displays its components
  88.      * from left to right.
  89.      *
  90.      * @return the box
  91.      */
  92.     public static Box createHorizontalBox() {
  93.     return new Box(BoxLayout.X_AXIS);
  94.     }
  95.  
  96.     /**
  97.      * Creates a <code>Box</code> that displays its components
  98.      * from top to bottom.
  99.      *
  100.      * @return the box
  101.      */
  102.     public static Box createVerticalBox() {
  103.     return new Box(BoxLayout.Y_AXIS);
  104.     }
  105.  
  106.     /**
  107.      * Creates an invisible component that's always the specified size.
  108.      * <!-- WHEN WOULD YOU USE THIS AS OPPOSED TO A STRUT? -->
  109.      *
  110.      * @param d the dimensions of the invisible component
  111.      * @return the component
  112.      * @see #createGlue
  113.      * @see #createHorizontalStrut
  114.      * @see #createVerticalStrut
  115.      */
  116.     public static Component createRigidArea(Dimension d) {
  117.     return new Filler(d, d, d);
  118.     }
  119.  
  120.     /**
  121.      * Creates an invisible, fixed-width component.
  122.      * In a horizontal box, 
  123.      * you typically use this method 
  124.      * to force a certain amount of space between two components.
  125.      * In a vertical box,
  126.      * you might use this method 
  127.      * to force the box to be at least the specified width.
  128.      * The invisible component has no height
  129.      * unless excess space is available,
  130.      * in which case it takes its share of available space,
  131.      * just like any other component that has no maximum height.
  132.      *
  133.      * @param width the width of the invisible component, in pixels >= 0
  134.      * @return the component
  135.      * @see #createVerticalStrut
  136.      * @see #createGlue
  137.      * @see #createRigidArea
  138.      */
  139.     public static Component createHorizontalStrut(int width) {
  140.     // PENDING(jeff) change to Integer.MAX_VALUE. This hasn't been done
  141.     // to date because BoxLayout alignment breaks.
  142.     return new Filler(new Dimension(width,0), new Dimension(width,0), 
  143.               new Dimension(width, Short.MAX_VALUE));
  144.     }
  145.  
  146.     /**
  147.      * Creates an invisible, fixed-height component.
  148.      * In a vertical box, 
  149.      * you typically use this method
  150.      * to force a certain amount of space between two components.
  151.      * In a horizontal box,
  152.      * you might use this method 
  153.      * to force the box to be at least the specified height.
  154.      * The invisible component has no width
  155.      * unless excess space is available,
  156.      * in which case it takes its share of available space,
  157.      * just like any other component that has no maximum width.
  158.      *
  159.      * @param height the height of the invisible component, in pixels >= 0
  160.      * @return the component
  161.      * @see #createHorizontalStrut
  162.      * @see #createGlue
  163.      * @see #createRigidArea
  164.      */
  165.     public static Component createVerticalStrut(int height) {
  166.     // PENDING(jeff) change to Integer.MAX_VALUE. This hasn't been done
  167.     // to date because BoxLayout alignment breaks.
  168.     return new Filler(new Dimension(0,height), new Dimension(0,height), 
  169.               new Dimension(Short.MAX_VALUE, height));
  170.     }
  171.  
  172.     /**
  173.      * Creates an invisible "glue" component 
  174.      * that can be useful in a Box
  175.      * whose visible components have a maximum width
  176.      * (for a horizontal box)
  177.      * or height (for a vertical box).
  178.      * You can think of the glue component
  179.      * as being a gooey substance
  180.      * that expands as much as necessary
  181.      * to fill the space between its neighboring components.
  182.      *
  183.      * <p>
  184.      *
  185.      * For example, suppose you have
  186.      * a horizontal box that contains two fixed-size components.
  187.      * If the box gets extra space,
  188.      * the fixed-size components won't become larger,
  189.      * so where does the extra space go?
  190.      * Without glue,
  191.      * the extra space goes to the right of the second component.
  192.      * If you put glue between the fixed-size components,
  193.      * then the extra space goes there.
  194.      * If you put glue before the first fixed-size component,
  195.      * the extra space goes there,
  196.      * and the fixed-size components are shoved against the right
  197.      * edge of the box.
  198.      * If you put glue before the first fixed-size component
  199.      * and after the second fixed-size component,
  200.      * the fixed-size components are centered in the box.
  201.      *
  202.      * <p>
  203.      *
  204.      * To use glue,
  205.      * call <code>Box.createGlue</code>
  206.      * and add the returned component to a container.
  207.      * The glue component has no minimum or preferred size,
  208.      * so it takes no space unless excess space is available.
  209.      * If excess space is available, 
  210.      * then the glue component takes its share of available
  211.      * horizontal or vertical space,
  212.      * just like any other component that has no maximum width or height.
  213.      *
  214.      * @return the component
  215.      */
  216.     public static Component createGlue() {
  217.     // PENDING(jeff) change to Integer.MAX_VALUE. This hasn't been done
  218.     // to date because BoxLayout alignment breaks.
  219.     return new Filler(new Dimension(0,0), new Dimension(0,0), 
  220.               new Dimension(Short.MAX_VALUE, Short.MAX_VALUE));
  221.     }
  222.  
  223.     /**
  224.      * Creates a horizontal glue component.
  225.      *
  226.      * @return the component
  227.      */
  228.     public static Component createHorizontalGlue() {
  229.     // PENDING(jeff) change to Integer.MAX_VALUE. This hasn't been done
  230.     // to date because BoxLayout alignment breaks.
  231.     return new Filler(new Dimension(0,0), new Dimension(0,0), 
  232.               new Dimension(Short.MAX_VALUE, 0));
  233.     }
  234.  
  235.     /**
  236.      * Creates a vertical glue component.
  237.      *
  238.      * @return the component
  239.      */
  240.     public static Component createVerticalGlue() {
  241.     // PENDING(jeff) change to Integer.MAX_VALUE. This hasn't been done
  242.     // to date because BoxLayout alignment breaks.
  243.     return new Filler(new Dimension(0,0), new Dimension(0,0), 
  244.               new Dimension(0, Short.MAX_VALUE));
  245.     }
  246.  
  247.     /**
  248.      * Throws an AWTError, since a Box can use only a BoxLayout.
  249.      *
  250.      * @param l the layout manager to use
  251.      */
  252.     public void setLayout(LayoutManager l) {
  253.     throw new AWTError("Illegal request");
  254.     }
  255.  
  256.  
  257.     /**
  258.      * An implementation of a lightweight component that participates in
  259.      * layout but has no view.
  260.      * <p>
  261.      * Warning: serialized objects of this class will not be compatible with
  262.      * future swing releases.  The current serialization support is appropriate
  263.      * for short term storage or RMI between Swing1.0 applications.  It will
  264.      * not be possible to load serialized Swing1.0 objects with future releases
  265.      * of Swing.  The JDK1.2 release of Swing will be the compatibility
  266.      * baseline for the serialized form of Swing objects.
  267.      */
  268.     public static class Filler extends Component {
  269.  
  270.     /**
  271.      * Constructor to create shape with the given size ranges.
  272.      *
  273.      * @param min   Minimum size
  274.      * @param pref  Preferred size
  275.      * @param max   Maximum size
  276.      */
  277.         public Filler(Dimension min, Dimension pref, Dimension max) {
  278.         reqMin = min;
  279.         reqPref = pref;
  280.         reqMax = max;
  281.     }
  282.  
  283.     /**
  284.      * Change the size requests for this shape.  An invalidate() is
  285.      * propagated upward as a result so that layout will eventually
  286.      * happen with using the new sizes.
  287.      *
  288.      * @param min   Value to return for getMinimumSize
  289.      * @param pref  Value to return for getPreferredSize
  290.      * @param max   Value to return for getMaximumSize
  291.      */
  292.         public void changeShape(Dimension min, Dimension pref, Dimension max) {
  293.         reqMin = min;
  294.         reqPref = pref;
  295.         reqMax = max;
  296.         invalidate();
  297.     }
  298.  
  299.     // ---- Component methods ------------------------------------------
  300.  
  301.         /**
  302.          * Returns the minimum size of the component.
  303.          *
  304.          * @return the size
  305.          */
  306.         public Dimension getMinimumSize() {
  307.         return reqMin;
  308.     }
  309.  
  310.         /**
  311.          * Returns the preferred size of the component.
  312.          *
  313.          * @return the size
  314.          */
  315.         public Dimension getPreferredSize() {
  316.         return reqPref;
  317.     }
  318.  
  319.         /**
  320.          * Returns the maximum size of the component.
  321.          *
  322.          * @return the size
  323.          */
  324.         public Dimension getMaximumSize() {
  325.         return reqMax;
  326.     }
  327.  
  328.     // ---- member variables ---------------------------------------
  329.  
  330.         private Dimension reqMin;
  331.         private Dimension reqPref;
  332.         private Dimension reqMax;
  333.  
  334. /////////////////
  335. // Accessibility support for Box$Filler
  336. ////////////////
  337.  
  338.         /**
  339.          * The currently set AccessibleContext object.
  340.          */
  341.         protected AccessibleContext accessibleContext = null;
  342.  
  343.         /**
  344.          * Gets the AccessibleContext associated with this Component.
  345.          * Creates a new context if necessary.
  346.          *
  347.          * @return the AccessibleContext of this Component
  348.          */
  349.         public AccessibleContext getAccessibleContext() {
  350.         if (accessibleContext == null) {
  351.         accessibleContext = new AccessibleBoxFiller();
  352.         }
  353.         return accessibleContext;
  354.         }
  355.  
  356.     protected class AccessibleBoxFiller extends AccessibleContext
  357.         implements Serializable, AccessibleComponent {
  358.  
  359.             // AccessibleContext methods
  360.             //
  361.             /**
  362.              * Gets the role of this object.
  363.              *
  364.              * @return an instance of AccessibleRole describing the role of
  365.              *   the object (AccessibleRole.FILLER)
  366.              * @see AccessibleRole
  367.              */
  368.             public AccessibleRole getAccessibleRole() {
  369.                 return AccessibleRole.FILLER;
  370.             }
  371.  
  372.             /**
  373.              * Gets the state of this object.
  374.              *
  375.              * @return an instance of AccessibleStateSet containing the current 
  376.              *   state set of the object
  377.              * @see AccessibleState
  378.              */
  379.             public AccessibleStateSet getAccessibleStateSet() {
  380.                 return SwingUtilities.getAccessibleStateSet(Filler.this);
  381.             }
  382.     
  383.             /**
  384.              * Get the Accessible parent of this object.  If the parent of this
  385.              * object implements Accessible, this method should simply return
  386.              * getParent().
  387.              *
  388.              * @return the Accessible parent of this object; null if this
  389.              *   object does not have an Accessible parent
  390.              */
  391.             public Accessible getAccessibleParent() {
  392.                 Container parent = getParent();
  393.                 if (parent instanceof Accessible) {
  394.                     return (Accessible) parent;
  395.                 } else {
  396.                     return null;
  397.                 }
  398.             }
  399.     
  400.             /**
  401.              * Gets the index of this object in its accessible parent. 
  402.              *
  403.              * @return the index of this object in its parent >= 0; -1 if this 
  404.              *   object does not have an accessible parent.
  405.              * @see #getAccessibleParent
  406.              */
  407.             public int getAccessibleIndexInParent() {
  408.                 return SwingUtilities.getAccessibleIndexInParent(Filler.this);
  409.             }
  410.     
  411.             /**
  412.              * Returns the number of accessible children in the object.  If all
  413.              * of the children of this object implement Accessible, then this
  414.              * method should return the number of children of this object.
  415.              *
  416.              * @return the number of accessible children in the object >= 0
  417.              */
  418.             public int getAccessibleChildrenCount() {
  419.                 return SwingUtilities.getAccessibleChildrenCount(Filler.this);
  420.             }
  421.     
  422.             /**
  423.              * Returns the nth Accessible child of the object.  
  424.              *
  425.              * @param i zero-based index of child
  426.              * @return the nth Accessible child of the object, null if none
  427.              */
  428.             public Accessible getAccessibleChild(int i) {
  429.                 return SwingUtilities.getAccessibleChild(Filler.this,i);
  430.             }
  431.         
  432.             /**
  433.              * Returns the locale of this object.
  434.              *
  435.              * @return the locale of this object
  436.              */
  437.             public Locale getLocale() {
  438.                 return Filler.this.getLocale();
  439.             }
  440.     
  441.             /**
  442.              * Gets the AccessibleComponent associated with this object if one
  443.              * exists.  Otherwise return null.
  444.              *
  445.              * @return the component
  446.              */
  447.         public AccessibleComponent getAccessibleComponent() {
  448.         return this;
  449.         }
  450.     
  451.     
  452.             // AccessibleComponent methods
  453.             //
  454.             /**
  455.              * Gets the background color of this object.
  456.              *
  457.              * @return the background color, if supported, of the object; 
  458.              * otherwise, null
  459.              */
  460.             public Color getBackground() {
  461.                 return Filler.this.getBackground();
  462.             }
  463.     
  464.             /**
  465.              * Sets the background color of this object.
  466.              *
  467.              * @param c the new Color for the background, null if none
  468.              */
  469.             public void setBackground(Color c) {
  470.                 Filler.this.setBackground(c);
  471.             }
  472.     
  473.             /**
  474.              * Gets the foreground color of this object.
  475.              *
  476.              * @return the foreground color, if supported, of the object; 
  477.              * otherwise, null
  478.              */
  479.             public Color getForeground() {
  480.                 return Filler.this.getForeground();
  481.             }
  482.     
  483.             /**
  484.              * Sets the foreground color of this object.
  485.              *
  486.              * @param c the new Color for the foreground, null if none
  487.              */
  488.             public void setForeground(Color c) {
  489.                 Filler.this.setForeground(c);
  490.             }
  491.     
  492.             /**
  493.              * Gets the Cursor of this object.
  494.              *
  495.              * @return the Cursor, if supported, of the object; otherwise, null
  496.              */
  497.             public Cursor getCursor() {
  498.                 return Filler.this.getCursor();
  499.             }
  500.     
  501.             /**
  502.              * Set the Cursor of this object.
  503.              *
  504.              * @param cursor the new Cursor for the object, null if none
  505.              */
  506.             public void setCursor(Cursor cursor) {
  507.                 Filler.this.setCursor(cursor);
  508.             }
  509.     
  510.             /**
  511.              * Gets the Font of this object.
  512.              *
  513.              * @return the Font,if supported, for the object; otherwise, null
  514.              */
  515.             public Font getFont() {
  516.                 return Filler.this.getFont();
  517.             }
  518.     
  519.             /**
  520.              * Sets the Font of this object.
  521.              *
  522.              * @param f the new Font for the object, null if none
  523.              */
  524.             public void setFont(Font f) {
  525.                 Filler.this.setFont(f);
  526.             }
  527.     
  528.             /**
  529.              * Gets the FontMetrics of this object.
  530.              *
  531.              * @param f the Font, null if none
  532.              * @return the FontMetrics, if supported, the object;
  533.              *   otherwise, null
  534.              * @see getFont
  535.              */
  536.             public FontMetrics getFontMetrics(Font f) {
  537.                 return Filler.this.getFontMetrics(f);
  538.             }
  539.     
  540.             /**
  541.              * Determines if the object is enabled.
  542.              *
  543.              * @return true if object is enabled; otherwise, false
  544.              */
  545.             public boolean isEnabled() {
  546.                 return Filler.this.isEnabled();
  547.             }
  548.     
  549.             /**
  550.              * Sets the enabled state of the object.
  551.              *
  552.              * @param b if true, enables this object; otherwise, disables it 
  553.              */
  554.             public void setEnabled(boolean b) {
  555.                 Filler.this.setEnabled(b);
  556.             }
  557.             
  558.             /**
  559.              * Determines if the object is visible.  Note: this means that the
  560.              * object intends to be visible; however, it may not in fact be
  561.              * showing on the screen because one of the objects that this object
  562.              * is contained by is not visible.  To determine if an object is
  563.              * showing on the screen, use isShowing().
  564.              *
  565.              * @return true if object is visible; otherwise, false
  566.              */
  567.             public boolean isVisible() {
  568.                 return Filler.this.isVisible();
  569.             }
  570.     
  571.             /**
  572.              * Sets the visible state of the object.
  573.              *
  574.              * @param b if true, shows this object; otherwise, hides it 
  575.              */
  576.             public void setVisible(boolean b) {
  577.                 Filler.this.setVisible(b);
  578.             }
  579.     
  580.             /**
  581.              * Determines if the object is showing.  This is determined by
  582.              * checking the visibility of the object and ancestors of the
  583.              * object.  Note: this will return true even if the object is
  584.              * obscured by another (for example, it happens to be
  585.              * underneath a menu that was pulled down).
  586.              *
  587.              * @return true if object is showing; otherwise, false
  588.              */
  589.             public boolean isShowing() {
  590.                 return Filler.this.isShowing();
  591.             }
  592.     
  593.             /** 
  594.              * Checks whether the specified point is within this object's
  595.              * bounds, where the point's x and y coordinates are defined to
  596.              * be relative to the coordinate system of the object. 
  597.              *
  598.              * @param p the Point relative to the coordinate system of
  599.              *   the object
  600.              * @return true if object contains Point; otherwise false
  601.              */
  602.             public boolean contains(Point p) {
  603.                 return Filler.this.contains(p);
  604.             }
  605.         
  606.             /** 
  607.              * Returns the location of the object on the screen.
  608.              *
  609.              * @return location of object on screen; can be null if this object
  610.              * is not on the screen
  611.              */
  612.             public Point getLocationOnScreen() {
  613.                 return Filler.this.getLocationOnScreen();
  614.             }
  615.     
  616.             /** 
  617.              * Gets the location of the object relative to the parent in the
  618.              * form of a point specifying the object's top-left corner in
  619.              * the screen's coordinate space.
  620.              *
  621.              * @return An instance of Point representing the top-left corner of 
  622.              * the objects's bounds in the coordinate space of the screen;
  623.              * null if this object or its parent are not on the screen
  624.              */
  625.             public Point getLocation() {
  626.                 return Filler.this.getLocation();
  627.             }
  628.     
  629.             /** 
  630.              * Sets the location of the object relative to the parent.
  631.              *
  632.              * @param p the location to be set
  633.              */
  634.             public void setLocation(Point p) {
  635.                 Filler.this.setLocation(p);
  636.             }
  637.     
  638.             /** 
  639.              * Gets the bounds of this object in the form of a Rectangle
  640.              * object.  The bounds specify this object's width, height,
  641.              * and location relative to its parent. 
  642.              *
  643.              * @return A rectangle indicating this component's bounds; null if 
  644.              * this object is not on the screen.
  645.              */
  646.             public Rectangle getBounds() {
  647.                 return Filler.this.getBounds();
  648.             }
  649.     
  650.             /** 
  651.              * Sets the bounds of this object in the form of a Rectangle
  652.              * object.  The bounds specify this object's width, height,
  653.              * and location relative to its parent.
  654.              *      
  655.              * @param r a rectangle indicating this component's bounds
  656.              */
  657.             public void setBounds(Rectangle r) {
  658.                 Filler.this.setBounds(r);
  659.             }
  660.     
  661.             /** 
  662.              * Returns the size of this object in the form of a Dimension
  663.              * object.  The height field of the Dimension object contains
  664.              * this objects's height, and the width field of the Dimension
  665.              * object contains this object's width. 
  666.              *
  667.              * @return A Dimension object that indicates the size of this 
  668.              * component; null if this object is not on the screen
  669.              */
  670.             public Dimension getSize() {
  671.                 return Filler.this.getSize();
  672.             }
  673.     
  674.             /** 
  675.              * Resizes this object.
  676.              *      
  677.              * @param d - The dimension specifying the new size of the object. 
  678.              */
  679.             public void setSize(Dimension d) {
  680.                 Filler.this.setSize(d);
  681.             }
  682.     
  683.             /**
  684.              * Returns the Accessible child, if one exists, contained at the
  685.              * local coordinate Point.
  686.              *
  687.              * @param p The point defining the top-left corner of the
  688.              * Accessible, given in the coordinate space of the object's parent. 
  689.              * @return the Accessible, if it exists, at the specified location; 
  690.              *   else null
  691.              */
  692.             public Accessible getAccessibleAt(Point p) {
  693.                 return SwingUtilities.getAccessibleAt(Filler.this,p);
  694.             }
  695.     
  696.             /**
  697.              * Returns whether this object can accept focus or not.
  698.              *
  699.              * @return true if object can accept focus; otherwise false
  700.              */
  701.             public boolean isFocusTraversable() {
  702.                 return Filler.this.isFocusTraversable();
  703.             }
  704.     
  705.             /**
  706.              * Requests focus for this object.
  707.              */
  708.             public void requestFocus() {
  709.                 Filler.this.requestFocus();
  710.             }
  711.     
  712.             /**
  713.              * Adds the specified listener to receive focus events from this 
  714.              * component. 
  715.              *
  716.              * @param l the focus listener
  717.              */
  718.             public void addFocusListener(FocusListener l) {
  719.                 Filler.this.addFocusListener(l);
  720.             }
  721.     
  722.             /**
  723.              * Removes the specified listener so it no longer receives focus 
  724.              * events from this component.
  725.              *
  726.              * @param l the focus listener
  727.              */
  728.             public void removeFocusListener(FocusListener l) {
  729.                 Filler.this.removeFocusListener(l);
  730.             }
  731.         }
  732.     }
  733.  
  734. /////////////////
  735. // Accessibility support for Box
  736. ////////////////
  737.  
  738.     /**
  739.      * The currently set AccessibleContext object.
  740.      */
  741.     protected AccessibleContext accessibleContext = null;
  742.  
  743.     /**
  744.      * Get the AccessibleContext associated with this JComponent.
  745.      * Creates a new context if necessary.
  746.      *
  747.      * @return the AccessibleContext of this JComponent
  748.      */
  749.     public AccessibleContext getAccessibleContext() {
  750.     if (accessibleContext == null) {
  751.         accessibleContext = new AccessibleBox();
  752.     }
  753.     return accessibleContext;
  754.     }
  755.  
  756.     protected class AccessibleBox extends AccessibleContext
  757.     implements Serializable, AccessibleComponent {
  758.  
  759.         // AccessibleContext methods
  760.         //
  761.         /**
  762.          * Gets the role of this object.
  763.          *
  764.          * @return an instance of AccessibleRole describing the role of the 
  765.      *   object (AccessibleRole.FILLER)
  766.          * @see AccessibleRole
  767.          */
  768.         public AccessibleRole getAccessibleRole() {
  769.             return AccessibleRole.FILLER;
  770.         }
  771.  
  772.         /**
  773.          * Gets the state of this object.
  774.          *
  775.          * @return an instance of AccessibleStateSet containing the current 
  776.      * state set of the object
  777.          * @see AccessibleState
  778.          */
  779.         public AccessibleStateSet getAccessibleStateSet() {
  780.         return SwingUtilities.getAccessibleStateSet(Box.this);
  781.         }
  782.  
  783.         /**
  784.          * Gets the Accessible parent of this object.  If the parent of this
  785.          * object implements Accessible, this method should simply return
  786.          * getParent().
  787.          *
  788.          * @return the Accessible parent of this object -- can be null if this
  789.          *   object does not have an Accessible parent
  790.          */
  791.         public Accessible getAccessibleParent() {
  792.             Container parent = getParent();
  793.             if (parent instanceof Accessible) {
  794.                 return (Accessible) parent;
  795.             } else {
  796.                 return null;
  797.             }
  798.         }
  799.  
  800.         /**
  801.          * Gets the index of this object in its accessible parent. 
  802.          *
  803.          * @return the index of this object in its parent >= 0; -1 if this 
  804.          *   object does not have an accessible parent.
  805.          * @see #getAccessibleParent
  806.          */
  807.         public int getAccessibleIndexInParent() {
  808.         return SwingUtilities.getAccessibleIndexInParent(Box.this);
  809.         }
  810.  
  811.         /**
  812.          * Returns the number of accessible children in the object.  If all
  813.          * of the children of this object implement Accessible, then this
  814.          * method should return the number of children of this object.
  815.          *
  816.          * @return the number of accessible children in the object >= 0.
  817.          */
  818.         public int getAccessibleChildrenCount() {
  819.         return SwingUtilities.getAccessibleChildrenCount(Box.this);
  820.         }
  821.  
  822.         /**
  823.          * Return the nth Accessible child of the object.  
  824.          *
  825.          * @param i zero-based index of child
  826.          * @return the nth Accessible child of the object, or null
  827.          */
  828.         public Accessible getAccessibleChild(int i) {
  829.             return SwingUtilities.getAccessibleChild(Box.this,i);
  830.         }
  831.  
  832.         /**
  833.          * Returns the locale of this object.
  834.      *
  835.          * @return the locale of this object
  836.          */
  837.         public Locale getLocale() {
  838.             return Box.this.getLocale();
  839.         }
  840.  
  841.         /**
  842.          * Gets the AccessibleComponent associated with this object if one
  843.          * exists.  Otherwise return null.
  844.          *
  845.          * @return the component
  846.          */
  847.     public AccessibleComponent getAccessibleComponent() {
  848.         return this;
  849.     }
  850.  
  851.  
  852.         // AccessibleComponent methods
  853.         //
  854.         /**
  855.          * Gets the background color of this object.
  856.          *
  857.          * @return the background color, if supported, of the object; 
  858.          * otherwise, null
  859.          */
  860.         public Color getBackground() {
  861.         return Box.this.getBackground();
  862.     }
  863.  
  864.         /**
  865.          * Sets the background color of this object.
  866.          *
  867.          * @param c the new Color for the background, null if none
  868.          */
  869.         public void setBackground(Color c) {
  870.         Box.this.setBackground(c);
  871.     }
  872.  
  873.         /**
  874.          * Gets the foreground color of this object.
  875.          *
  876.          * @return the foreground color, if supported, of the object; 
  877.          *   otherwise, null
  878.          */
  879.         public Color getForeground() {
  880.         return Box.this.getForeground();
  881.     }
  882.  
  883.         /**
  884.          * Sets the foreground color of this object.
  885.          *
  886.          * @param c the new Color for the foreground, null if none
  887.          */
  888.         public void setForeground(Color c) {
  889.         Box.this.setForeground(c);
  890.     }
  891.  
  892.         /**
  893.          * Gets the Cursor of this object.
  894.          *
  895.          * @return the Cursor, if supported, of the object; otherwise, null
  896.          */
  897.         public Cursor getCursor() {
  898.         return Box.this.getCursor();
  899.     }
  900.  
  901.         /**
  902.          * Sets the Cursor of this object.
  903.          *
  904.          * @param cursor the new Cursor for the object, null if none
  905.          */
  906.         public void setCursor(Cursor cursor) {
  907.         Box.this.setCursor(cursor);
  908.     }
  909.  
  910.         /**
  911.          * Gets the Font of this object.
  912.          *
  913.          * @return the Font,if supported, for the object; otherwise, null
  914.          */
  915.         public Font getFont() {
  916.         return Box.this.getFont();
  917.     }
  918.  
  919.         /**
  920.          * Sets the Font of this object.
  921.          *
  922.          * @param f the new Font for the object, null if none
  923.          */
  924.         public void setFont(Font f) {
  925.         Box.this.setFont(f);
  926.     }
  927.  
  928.         /**
  929.          * Gets the FontMetrics of this object.
  930.          *
  931.          * @param f the Font
  932.          * @return the FontMetrics, if supported, the object; otherwise, null
  933.          * @see getFont
  934.          */
  935.         public FontMetrics getFontMetrics(Font f) {
  936.         return Box.this.getFontMetrics(f);
  937.     }
  938.  
  939.         /**
  940.          * Determines if the object is enabled.
  941.          *
  942.          * @return true if object is enabled; otherwise, false
  943.          */
  944.         public boolean isEnabled() {
  945.         return Box.this.isEnabled();
  946.     }
  947.  
  948.         /**
  949.          * Sets the enabled state of the object.
  950.          *
  951.          * @param b if true, enables this object; otherwise, disables it 
  952.          */
  953.         public void setEnabled(boolean b) {
  954.         Box.this.setEnabled(b);
  955.     }
  956.     
  957.         /**
  958.          * Determines if the object is visible.  Note: this means that the
  959.          * object intends to be visible; however, it may not in fact be
  960.          * showing on the screen because one of the objects that this object
  961.          * is contained by is not visible.  To determine if an object is
  962.          * showing on the screen, use isShowing().
  963.          *
  964.          * @return true if object is visible; otherwise, false
  965.          */
  966.         public boolean isVisible() {
  967.         return Box.this.isVisible();
  968.     }
  969.  
  970.         /**
  971.          * Sets the visible state of the object.
  972.          *
  973.          * @param b if true, shows this object; otherwise, hides it 
  974.          */
  975.         public void setVisible(boolean b) {
  976.         Box.this.setVisible(b);
  977.     }
  978.  
  979.         /**
  980.          * Determines if the object is showing.  This is determined by checking
  981.          * the visibility of the object and ancestors of the object.  Note: 
  982.      * this will return true even if the object is obscured by another 
  983.      * (for example, it happens to be underneath a menu that was pulled 
  984.      * down).
  985.          *
  986.          * @return true if object is showing; otherwise, false
  987.          */
  988.         public boolean isShowing() {
  989.         return Box.this.isShowing();
  990.     }
  991.  
  992.         /** 
  993.          * Checks whether the specified point is within this object's bounds,
  994.          * where the point's x and y coordinates are defined to be relative to 
  995.      * the coordinate system of the object. 
  996.          *
  997.          * @param p the Point relative to the coordinate system of the object
  998.          * @return true if object contains Point; otherwise false
  999.          */
  1000.         public boolean contains(Point p) {
  1001.         return Box.this.contains(p);
  1002.     }
  1003.     
  1004.         /** 
  1005.          * Returns the location of the object on the screen.
  1006.          *
  1007.          * @return location of object on screen -- can be null if this object
  1008.          * is not on the screen
  1009.          */
  1010.         public Point getLocationOnScreen() {
  1011.         return Box.this.getLocationOnScreen();
  1012.     }
  1013.  
  1014.         /** 
  1015.          * Gets the location of the object relative to the parent in the form 
  1016.          * of a point specifying the object's top-left corner in the screen's 
  1017.          * coordinate space.
  1018.          *
  1019.          * @return An instance of Point representing the top-left corner of 
  1020.      *   the objects's bounds in the coordinate space of the screen; null if
  1021.          *   this object or its parent are not on the screen
  1022.          */
  1023.     public Point getLocation() {
  1024.         return Box.this.getLocation();
  1025.     }
  1026.  
  1027.         /** 
  1028.          * Sets the location of the object relative to the parent.
  1029.          *
  1030.          * @param p the location to be set
  1031.          */
  1032.         public void setLocation(Point p) {
  1033.         Box.this.setLocation(p);
  1034.     }
  1035.  
  1036.         /** 
  1037.          * Gets the bounds of this object in the form of a Rectangle object. 
  1038.          * The bounds specify this object's width, height, and location
  1039.          * relative to its parent. 
  1040.          *
  1041.          * @return A rectangle indicating this component's bounds; null if 
  1042.      * this object is not on the screen.
  1043.          */
  1044.         public Rectangle getBounds() {
  1045.         return Box.this.getBounds();
  1046.     }
  1047.  
  1048.         /** 
  1049.          * Sets the bounds of this object in the form of a Rectangle object. 
  1050.          * The bounds specify this object's width, height, and location
  1051.          * relative to its parent.
  1052.          *    
  1053.          * @param r a rectangle indicating this component's bounds
  1054.          */
  1055.         public void setBounds(Rectangle r) {
  1056.         Box.this.setBounds(r);
  1057.     }
  1058.  
  1059.         /** 
  1060.          * Returns the size of this object in the form of a Dimension object. 
  1061.          * The height field of the Dimension object contains this objects's
  1062.          * height, and the width field of the Dimension object contains this 
  1063.      * object's width. 
  1064.          *
  1065.          * @return A Dimension object that indicates the size of this 
  1066.      *   component; null if this object is not on the screen
  1067.          */
  1068.         public Dimension getSize() {
  1069.         return Box.this.getSize();
  1070.     }
  1071.  
  1072.         /** 
  1073.          * Resizes this object.
  1074.          *    
  1075.          * @param d - The dimension specifying the new size of the object. 
  1076.          */
  1077.         public void setSize(Dimension d) {
  1078.         Box.this.setSize(d);
  1079.     }
  1080.  
  1081.         /**
  1082.          * Returns the Accessible child, if one exists, contained at the local
  1083.      * coordinate Point.
  1084.          *
  1085.          * @param p The point defining the top-left corner of the Accessible, 
  1086.      *   given in the coordinate space of the object's parent. 
  1087.          * @return the Accessible, if it exists, at the specified location; 
  1088.      *   else null
  1089.          */
  1090.         public Accessible getAccessibleAt(Point p) {
  1091.         return SwingUtilities.getAccessibleAt(Box.this,p);
  1092.     }
  1093.  
  1094.         /**
  1095.          * Determines whether this object can accept focus or not.
  1096.          *
  1097.          * @return true if object can accept focus; otherwise false
  1098.          */
  1099.         public boolean isFocusTraversable() {
  1100.         return Box.this.isFocusTraversable();
  1101.     }
  1102.  
  1103.         /**
  1104.          * Requests focus for this object.
  1105.          */
  1106.         public void requestFocus() {
  1107.         Box.this.requestFocus();
  1108.         }
  1109.  
  1110.         /**
  1111.          * Adds the specified focus listener to receive focus events from this 
  1112.          * component. 
  1113.          *
  1114.          * @param l the focus listener
  1115.          */
  1116.         public void addFocusListener(FocusListener l) {
  1117.         Box.this.addFocusListener(l);
  1118.     }
  1119.  
  1120.         /**
  1121.          * Removes the specified focus listener so it no longer receives focus 
  1122.          * events from this component.
  1123.          *
  1124.          * @param l the focus listener
  1125.          */
  1126.         public void removeFocusListener(FocusListener l) {
  1127.         Box.this.removeFocusListener(l);
  1128.     }
  1129.     } // inner class AccessibleBox
  1130. }
  1131.